package ua.races;

import ua.races.dao.RacesDaoImpl;
import ua.races.relultObjects.FullBet;
import ua.races.vo.*;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DBTest {
    private final RacesDaoImpl rc = new RacesDaoImpl();

    public static void main(String[] args) throws SQLException, IOException {
        DBTest test = new DBTest();
//        String l = "123";
//            System.out.println("l.hashCode() = " + l.hashCode());
        //  this should be called once per application start-stop lifecycle
        test.rc.start();

        test.doTestJdbc();


        //  this should be called once per application start-stop lifecycle
        test.rc.stop();


    }

    /**
     * some persistence code called via DataAccessObject
     */
    protected void doTestJdbc() {
        try {
//                final List<Horse> horses = rc.findAllHorses();
//                for (Horse horse : horses) {
//                    System.out.println("Id = " + horse.getHorseId() + " Alias = "+ horse.getHorseName());
//                }
//
//                System.out.println("horses.get(0).getHorseId() = " + horses.get(0).getHorseId());
//
//                final List<Race> races = rc.findAllRacesWithHorse(horses.get(1));
//                for (Race race : races) {
//                    System.out.println("Id = " + race.getRaceId() + " Date = "+ race.getRaceDate() +
//                    " Stadium = " + race.getStadium() + " Start time = " + race.getStartTime());
//                }

            //System.out.println("rc.synchronizeDbToJson(\"c:\\\\java\") = " + rc.synchronizeDbToJson("c:\\java\\JSONbravo"));

            // System.out.println("rc.synchronizeJsonToDb(\"c:\\java\\JSONbravo\") = " + rc.synchronizeJsonToDb("c:\\java\\JSONbravo"));
//                HashMap<Horse, ArrayList<Integer>> horses = rc.getHorseHistory();
//                System.out.println(horses);
//
//                List<Race> races = rc.findAllRaces();
//
//                List<Horse> horsesss = rc.getHorsesInRace(races.get(0));
//
//                System.out.println(horsesss);

            List<Bet> bets = rc.findAllBets();
            List<FullBet> fullBets = rc.getFullBets(bets);

            Race race = new Race();
            race.setStadium("STAD DE FRANCE");
            race.setRaceDate(Date.valueOf("2011-01-01"));
            race.setStartTime(Time.valueOf("10:00:00"));

            System.out.println("rc.addNewRace(race) = " + rc.addNewRace(race));

            Map<Horse, Map<Date, Integer>> results = rc.horseStatistics(5);
            //  List<Horse> horses = rc.findAllHorseInRace(race);


            Horse horse1 = new Horse();
            Horse horse2 = new Horse();
            Horse horse3 = new Horse();
            horse1.setHorseId(1l);
            horse2.setHorseId(2l);
            horse3.setHorseId(3l);

            HashMap<Race, HashMap<Horse, Integer>> raceResults = new HashMap<Race, HashMap<Horse, Integer>>();
            HashMap<Race, HashMap<Horse, Double>> raceCoefs = new HashMap<Race, HashMap<Horse, Double>>();


            HashMap<Horse, Integer> res = new HashMap<Horse, Integer>();
            res.put(horse1, 2);
            res.put(horse2, 1);
            res.put(horse3, 3);

            HashMap<Horse, Double> coef = new HashMap<Horse, Double>();

            coef.put(horse1, 1.1);
            coef.put(horse2, 1.2);
            coef.put(horse3, 1.3);

            List<Race> races = rc.findAllRacesForBet();
            System.out.println("races = " + races);

            raceCoefs.put(race, coef);

            //int r = rc.setResults(raceResults);
            // int r = rc.setCoefs(raceCoefs);

            Staff s = rc.findStaffByEmail("ou@staff.com");


            Client client = rc.findClientByEmail("akraievoy@gmail.com");
            //System.out.println(r);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}

